package com.ruijie.autotest.log.validation.paiboftp.wifitrack;

import com.minelx.landisk.filesystem.Paths;
import com.minelx.landisk.filesystem.core.Directory;
import com.minelx.landisk.filesystem.core.File;
import com.ruijie.autotest.log.common.crypto.*;
import com.ruijie.autotest.log.impl.parse.ColumnsAndValuesParser;
import com.ruijie.autotest.log.impl.parse.GridColumnsParser;
import com.ruijie.autotest.log.impl.parse.LinesParser;
import com.ruijie.autotest.log.impl.parse.ReduceEndCellsParser;
import com.ruijie.autotest.log.validation.hangzhoudewangxin.WIFILOGOUT.SingleValuesFileToTable;
import com.ruijie.autotest.log.validation.hangzhouxiruan.CompositeColumnVerification;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.ComponentScan;

import java.util.List;

import static com.minelx.landisk.filesystem.core.File.byExtension;

@SpringBootApplication
public class WifiTrackTest {

	private static final String PASSWORD = "12345678";

	private static final String IV_PASSWORD = "12345678";

	public static void main(String[] args) throws Exception {
		ConfigurableApplicationContext context = SpringApplication.run(WifiTrackTest.class, args);

		ColumnsAndValuesParser columnsAndValuesParser = new ColumnsAndValuesParser(
				new GridColumnsParser(" ", 0),
				new LinesParser("\r\n|\n"),
				new ReduceEndCellsParser("\u0001")
		);

		SingleValuesFileToTable fileToTable = new SingleValuesFileToTable(
				columnsAndValuesParser,
				Paths.of("/C:/Users/123/ZYH_HOME/Projects/IdeaProjects/NetSupervisor/src/test/resources/mappings/paiboftp/wifitrack/columns.txt")
		);

		ICryptoFactory cbcNoPadding = CBC.create(new DESAlgorithm(), PASSWORD, IV_PASSWORD, Padding.NO_PADDING).cryptoFactory();

		// FIXME 2021/1/15  wait for me!!!   composite
		List<File> decryptedFiles = ICryptoFactory.decryptedFiles(rawFiles(), Base64CryptoFactory.get().before(cbcNoPadding).decryption());

		CompositeColumnVerification manyVerification = new CompositeColumnVerification(context, fileToTable.mapToTables(decryptedFiles));
		manyVerification.verify();

		System.out.println("we done.");
	}

	private static List<File> rawFiles() {
		Directory rootDirectory = Paths.root("/D:/FTP/派博ftp/RJXYYH");
		return rootDirectory.childrenFiles()
				.filter(which -> !which.getName().startsWith("decrypted_")) // not starts with "decrypted_"
				.filter(which -> which.getName().contains("WIFITrack"))
				.filter(byExtension("zip")).all();
	}
}
